<?php
class v1_account{
    function info(){
    	$session=$this->yum->library('session');
		$information=$this->yum->model('information');
		$mation=$information->GMation(array('where'=>array('member ='=>$session->GVAR('member'))));
		if(!empty($mation)){
			$mation=reset($mation);
			$data['name']=$mation['name'];
			$data['IDcard']=$mation['IDcard'];
			$data['phone']=$mation['phone'];
			$data['msn']=$mation['msn'];
			$data['qq']=$mation['qq'];
		}
		if($this->yum->post('save',true)){
			$data['message']=array('result'=>false,'msg'=>array());
			$name=$this->yum->post('name',true);
			$IDcard=$this->yum->post('IDcard',true);
			$phone=$this->yum->post('phone',true);
			$msn=$this->yum->post('msn',true);
			$qq=$this->yum->post('qq',true);
			$helper=$this->yum->library('helper');
			if(strlen($name)==0){
				$data['message']['msg'][]='姓名不可为空.';
			}else if(!$helper->CPhone($phone)){
				$data['message']['msg'][]='您输入的联系电话不是一个有效的号码.';
			}else{
				if(empty($mation)){
					$affected=$information->IMation(array('member'=>$session->GVAR('member'),'name'=>$name,'IDcard'=>$IDcard,'phone'=>$phone,'msn'=>$msn,'qq'=>$qq));
				}else{
					$affected=$information->UMation(array('set'=>array('name ='=>$name,'IDcard ='=>$IDcard,'phone ='=>$phone,'msn ='=>$msn,'qq ='=>$qq),'where'=>array('member ='=>$session->GVAR('member'))));
				}
				if($affected!=1){
					$data['message']['msg'][]='请误重复提交.';
				}else{
					$data['name']=$name;
					$data['IDcard']=$IDcard;
					$data['phone']=$phone;
					$data['msn']=$msn;
					$data['qq']=$qq;
					$data['message']['result']=true;
					$data['message']['msg'][]='个人信息修改成功.';
				}
			}
		}
		$this->yum->set($data);
    	$this->yum->view('info.php');
    }
    function password(){
    	$session=$this->yum->library('session');
		if($this->yum->post('save',true)){
			$data['message']=array('result'=>false,'msg'=>array());
			$password=$this->yum->post('password',true);
			$new=$this->yum->post('new',true);
			$affirm=$this->yum->post('affirm',true);
			if(strlen($password)==0){
				$data['message']['msg'][]='旧密码不可为空.';
			}else if(preg_match("/[^a-zA-Z_0-9]/",$new)>0){
				$data['message']['msg'][]='密码只可为a-z;A-Z;0-9;_的组合';
			}else if(strlen($new)<6||strlen($new)>32){
				$data['message']['msg'][]='密码长度为6-32个字符.';
			}else if(($affirm!=$new)){
				$data['message']['msg'][]='您输入的新密码和确认密码不同.';
			}else if($password==$new){
				$data['message']['msg'][]='旧密码与新密码不可相同.';
			}else{
				$member=$this->yum->model('member');
				$affected=$member->UMember(array('set'=>array('password ='=>$new),'where'=>array('id ='=>$session->GVAR('member'),'password ='=>$password)));
				if($affected==1){
					$data['message']['result']=true;
					$data['message']['msg'][]='密码修改成功.';
				}else{
					$data['message']['msg'][]='你输入的旧密码与帐户不匹配,请注意大小写.';
				}
			}
			$this->yum->set($data);
		}
		$this->yum->view('password.php');
    }
}
?>